define(['./BaseView', '../models/ParticularView','../libs/extend', 'underscore'], function(BaseView, ParticularView, extend, _) {
    return BaseView.extend({
        themeData:null,
        events: {

        },
        //初始化
        initialize: function(){
            BaseView.prototype.initialize.apply(this, arguments);
            var content = $('<ul class="particular-main"></ul>');
            this.$el.append(content);
            this.themeData = new ParticularView();
            this.listenTo(this.themeData, 'change', this.onChange);
        },
        render:function(){
            var data = this.themeData.toJSON();
            this.createMain(data);
            return this;
        },
        //重新render
        onChange: function(){
            this.render();
        },
        createMain:function(data){
            var dataId = data.pk_record;//事物id
            var departments = data.deptname;//部门名称
            var username = data.username;//人员
            var project = data.project;//项目
            var reason = data.reason;//事由
            var projecttype = data.projecttype;//项目类型
            var province = data.province;//所属省区
            var branchcomp  = data.branchcomp ;//分公司
            var begindate = data.begindate;//起始日期
            var enddate = data.enddate;//结束日期
            var daysnum = data.daysnum;//天数
            var period = data.period;//季度
            var achievement = data.achievement;//阶段成果
            var manager = data.manager;//项目负责人
            var phone = data.phone;//项目负责人电话
            var projstatus = data.projstatus;//项目状态
            var iscollected = data.iscollected.value;//是否涉及收款
            var collectedamount = data.collectedamount;//收款金额
            var collectedtime = data.collectedtime;//收款时间
            var isinspected = data.isinspected.value;//是否涉及验收
            var inspecttime = data.inspecttime;//验收时间
            var expensetype = data.expensetype;//费用自理方式
            var expenseamount = data.expenseamount;//费用自理金额
            var remarks = data.remarks;//备注
            var attachments = data.attachments;//附件
            //处理数据
            if(iscollected == 'true'){
                iscollected = '是'
            }else{
                iscollected = '否'
            }
            if(isinspected == 'true'){
                isinspected = '是'
            }else{
                isinspected = '否'
            }
            if(phone == '无'){
                phone = '';
            }
            var contentItem = [
                '<li><span class="main-company">用友网络科技股份有限公司</span></li>',
                '<p class="line"></p>',
                '<li><span class="main-item">'+ project +'</span></li>',
                '<li class="main-people"><img src="../../images/people.svg" class="people" alt=""/><span class="main-name">'+ username +'</span></li>',
                '<li class="main-bumen"><span class="bumen">所属部门：</span><span class="main-departments">'+ departments +'</span></li>',
                '<p class="line_a"></p>',

                '<li class="cause">事由：<span class="main-cause">'+ reason +'</span></li>',
                '<li>项目所属分公司：<span class="main-filiale">'+ branchcomp +'</span></li>',
                '<li class="type">所属类型：<span class="main-type">'+ projecttype +'</span></li>',
                '<li class="province">所属省区：<span class="main-province">'+ province +'</span></li>',

                '<li>起始日期：<span class="main-date">'+ begindate +'</span></li>',
                '<li>结束日期：<span class="main-date">'+ enddate +'</span></li>',
                '<li class="dataNum">天数：<span class="main-date">'+ daysnum +'</span></li>',
                '<li class="dataNum">期间：<span class="main-season">'+ period +'</span></li>',
                '<li>阶段成果：<span class="main-resault">'+ achievement +'</span></li>',
                '<li>项目负责人：<span class="main- principal">'+ manager +'</span></li>',
                '<li>项目负责人电话：<span class="main-telNum">'+ phone +'</span></li>',
                '<li>项目状态：<span class="main-state">'+ projstatus +'</span></li>',
                '<p class="line_a"></p>',
                '<li>涉及收款：<span class="main-gathering">'+ iscollected +'</span></li>',
                '<li>预期收款金额：<a class="cor">￥</a><span class="main-sum">'+  collectedamount+'</span></li>',
                '<li>预期收款时间：<span class="main-sum-date">'+ collectedtime +'</span></li>',
                '<p class="line_a"></p>',
                '<li>涉及验收：<span class="main-accept">'+ isinspected +'</span></li>',
                '<li>验收时间：<span class="main-acceptDate">'+ inspecttime +'</span></li>',
                '<li>费用自理：<span class="main-cost">'+ expensetype +'</span></li>',
                '<li>费用金额：<a class="cor">￥</a><span class="main-costMoney">'+ expenseamount +'</span></li>',
                '<li>备注：<span class="main-remark">'+ remarks +'</span></li>',
                '<li class="accessary">附件：<div class="addacc"></div></li>'
            ].join('');
            this.$el.find('.particular-main').html(contentItem);

           //附件循环加载
            if(attachments.length==0){
                var  mainspan = '<span class="noAttachment">暂无附件</span>';
                this.$el.find('.addacc').append(mainspan)
            }else{
                for(var i=0;i<attachments.length;i++){
                    mainspan = '<p class="main-attachment">'+ attachments[i] +'</p>';
                    this.$el.find('.addacc').append(mainspan)
                }
            }

        }

    });
});

